package com.wk.contrller;

import com.wk.bean.PageInfo;
import com.wk.bean.WkVisit;
import com.wk.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/auth") // 这里添加了 /auth 前缀
@CrossOrigin(origins = "http://localhost:8080")
public class VisitController {
    @Autowired
    UserService userService;
    //医生分页查询
    @PostMapping("/listVisitWithPagination")
    public ResponseEntity<Map<String, Object>> listVisitWithPagination(@RequestBody Map<String, Object> queryParams) {
        int page = Integer.parseInt(queryParams.get("page").toString());
        int pageSize = Integer.parseInt(queryParams.get("pageSize").toString());

        PageInfo pageInfo = new PageInfo();
        pageInfo.setOffset((page - 1) * pageSize);
        pageInfo.setPageSize(pageSize);

        List<WkVisit> users = userService.listVisitWithPagination(pageInfo);

        Map<String, Object> response = new HashMap<>();
        if (users != null) {
            response.put("message", "成功获取用户列表。");
            response.put("users", users);
            return new ResponseEntity<>(response, HttpStatus.OK);
        } else {
            response.put("message", "未找到用户信息。");
            return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST);
        }
    }
}
